<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\UserContext;
use App\Http\Requests\UserLogin;
use App\Http\Requests\UserRegister;
use App\Http\Services\UserService;
use App\Http\Traits\ResponseJson;
use GenTux\Jwt\JwtToken;

class UserController extends Controller
{
    use ResponseJson;

    protected $userService;

    public function __construct(UserService $userService)
    {
        $this->userService = $userService;
    }

    public function loginPass(UserLogin $userLogin, JwtToken $jwtToken)
    {
        $data = $this->userService->loginPass($userLogin,$jwtToken);
        return $this->returnJson($data);
    }

    public function registerUser(UserRegister $userRegister)
    {
        $data = $this->userService->registerUser($userRegister);
        return $this->returnJson($data);
    }

    public function userInfo(UserContext $userContext)
    {
        $data = $this->userService->userInfo($userContext);
        return $this->returnJson($data);
    }

    public function miniLogin(JwtToken $jwtToken)
    {
        $data = $this->userService->miniLogin($jwtToken);
        return $this->returnJson($data);
    }

    /**
     * 退出登录
     * @param UserContext $userContext
     * @return \Illuminate\Http\JsonResponse
     */
    public function logout(UserContext $userContext)
    {
        $data = $this->userService->logout($userContext);
        return $this->returnJson($data);
    }

}
